import java.awt.Image;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;


public class Spielstein {

	private String spielstein = "spielstein.png";
	
	private int dx;
	private int dy;
	private int x;
	private int y;
	private Image image;
	
	public Spielstein() {
		ImageIcon icon = new ImageIcon(this.getClass().getResource(spielstein));
		image = icon.getImage();
		x = 10;
		y = 10;		
	}
	
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}
	
	public Image getImage() {
		return image;
	}
	
	public void move() {
		
		if (x > 600 || x < 10) {
			dx = 0;
			x = 10;
		}
		
		if (y > 640 || y < 10) {
			dy = 0;
			y = 10;
		}
		
		x = x + dx;
		y = y + dy;
	}
	
	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		
		if (keyCode == KeyEvent.VK_LEFT) {
			dx = -40;
		}
		
		if (keyCode == KeyEvent.VK_RIGHT){
			dx = 40;
		}
		
		if (keyCode == KeyEvent.VK_SPACE) {
			dy = 300;
		}
	}
	
	public void keyReleased(KeyEvent e) {
		int keyCode = e.getKeyCode();
		
		 if (keyCode == KeyEvent.VK_LEFT) {
	            dx = 0;
	     }

	     if (keyCode == KeyEvent.VK_RIGHT) {
	            dx = 0;
	     }

	     if (keyCode == KeyEvent.VK_SPACE) {
	            dy = 0;
	     }
	}
	
	
}
